//
//  ViewController.swift
//  SwiftTest
//
//  Created by midea on 16/3/8.
//  Copyright © 2016年 Vincent. All rights reserved.
//

import UIKit
import Foundation

class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {

    var titles : Array<String>?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        titles = ["Basic data type","Operator","String","Array","Dictionary","Control Flow","Function","Closures","Enum","Class And Struct","Property","Inherit","Initializers","Deinit","ARC","Optional Chaining","Type Checking","Nested Type","Extension","Protocol","Genericity","Advanced Operators"]
        
        let tableView = UITableView.init(frame: self.view.bounds, style: .grouped)
        tableView.dataSource = self
        tableView.delegate = self
        self.view.addSubview(tableView)
        tableView.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: "cell")
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return (titles?.count)!
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
        cell?.textLabel?.text = titles![indexPath.row]
        return cell!
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        
        switch indexPath.row {
        case 0:
            let vc : BasicDataTypeViewController = BasicDataTypeViewController()
            vc.title = titles![0]
            self.navigationController?.pushViewController(vc, animated: true)
        case 1:
            let vc : OperatorViewController = OperatorViewController()
            vc.title = titles![1]
            self.navigationController?.pushViewController(vc, animated: true)
        case 2:
            let vc : StringViewController = StringViewController()
            vc.title = titles![2]
            self.navigationController?.pushViewController(vc, animated: true)
        case 3:
            let vc : ArrayViewController = ArrayViewController()
            vc.title = titles![3]
            self.navigationController?.pushViewController(vc, animated: true)
        case 4:
            let vc : DictionaryViewController = DictionaryViewController()
            vc.title = titles![4]
            self.navigationController?.pushViewController(vc, animated: true)
        case 5:
            let vc : ControlFlowViewController = ControlFlowViewController()
            vc.title = titles![5]
            self.navigationController?.pushViewController(vc, animated: true)
        case 6:
            let vc : FunctionViewController = FunctionViewController()
            vc.title = titles![6]
            self.navigationController?.pushViewController(vc, animated: true)
        case 7:
            let vc : ClosuresViewController = ClosuresViewController()
            vc.title = titles![7]
            self.navigationController?.pushViewController(vc, animated: true)
        case 8:
            let vc : EnumViewController = EnumViewController()
            vc.title = titles![8]
            self.navigationController?.pushViewController(vc, animated: true)
        case 9:
            let vc : ClassStructViewController = ClassStructViewController()
            vc.title = titles![9]
            self.navigationController?.pushViewController(vc, animated: true)
        case 10:
            let vc : PropertyViewController = PropertyViewController()
            vc.title = titles![10]
            self.navigationController?.pushViewController(vc, animated: true)
        case 11:
            let vc : InheritViewController = InheritViewController()
            vc.title = titles![11]
            self.navigationController?.pushViewController(vc, animated: true)
        case 12:
            let vc : InitializerViewController = InitializerViewController()
            vc.title = titles![12]
            self.navigationController?.pushViewController(vc, animated: true)
        case 13:
            let vc : DeinitViewController = DeinitViewController()
            vc.title = titles![13]
            self.navigationController?.pushViewController(vc, animated: true)
        case 14:
            let vc : ARCViewController = ARCViewController()
            vc.title = titles![14]
            self.navigationController?.pushViewController(vc, animated: true)
        case 15:
            let vc : OptionalChainingViewController = OptionalChainingViewController()
            vc.title = titles![15]
            self.navigationController?.pushViewController(vc, animated: true)
        case 16:
            let vc : TypeCheckingViewController = TypeCheckingViewController()
            vc.title = titles![16]
            self.navigationController?.pushViewController(vc, animated: true)
        case 17:
            let vc : NestedTypeViewController = NestedTypeViewController()
            vc.title = titles![17]
            self.navigationController?.pushViewController(vc, animated: true)
        case 18:
            let vc : ExtensionViewController = ExtensionViewController()
            vc.title = titles![18]
            self.navigationController?.pushViewController(vc, animated: true)
        case 19:
            let vc : ProtocolViewController = ProtocolViewController()
            vc.title = titles![19]
            self.navigationController?.pushViewController(vc, animated: true)
        case 20:
            let vc : GenericityViewController = GenericityViewController()
            vc.title = titles![20]
            self.navigationController?.pushViewController(vc, animated: true)
        case 21:
            let vc :  AdvancedOperatorsViewController =  AdvancedOperatorsViewController()
            vc.title = titles![21]
            self.navigationController?.pushViewController(vc, animated: true)
        default:
            print("no any more")
        }
    }
}

